using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Shuriken.Core.UI.StandardUI
{
    public partial class ItemListView : UserControl
    {
        public ItemListView()
        {
            InitializeComponent();

            //lblSearchTerm.Text = string.Empty;
            ctrlItemListBox.DrawMode = DrawMode.OwnerDrawVariable;
        }

        //public string SearchTerm
        //{
        //    get
        //    {
        //        return lblSearchTerm.Text;
        //    }

        //    set
        //    {
        //        lblSearchTerm.Text = value;
        //    }
        //}

        internal void BeginUpdate()
        {
            ctrlItemListBox.BeginUpdate();
        }

        internal void EndUpdate()
        {
            ctrlItemListBox.EndUpdate();
        }

        internal void SetItems(Shuriken.Core.Store.SortedDisplayItemList DisplayItems)
        {
            ctrlItemListBox.Items.Clear();
            ctrlItemListBox.Items.AddRange(DisplayItems.ToArray());
        }

        /// <summary>
        /// Gets or Sets the selected index from the list
        /// </summary>
        public int SelectedIndex
        {
            get
            {
                return ctrlItemListBox.SelectedIndex;
            }
            set
            {
                ctrlItemListBox.SelectedIndex = value;
            }
        }

        private void ctrlItemListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            frmMain parentForm = (frmMain)this.FindForm();

            if (parentForm != null)
            {
                parentForm.DetailsSelectIndexChanged(ctrlItemListBox.SelectedIndex);
            }

            lblCountMeasure.Text = (ctrlItemListBox.SelectedIndex + 1) + " of " + ctrlItemListBox.Items.Count; 
        }

        private void ctrlItemListX_VisibleChanged(object sender, EventArgs e)
        {
            if (this.Visible)
            {
                ctrlItemListBox.Focus();
            }
        }
    }
}
